﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace GE.Objects
{
    public class Hero : Character
    {
        float atknum, defnum;
        public Hero(CharacterData data, Vector2 pos)
           : base(data, pos)
        {
            Random r = new Random();
            atknum = (65 + r.Next(16)) / 50.0f;
            defnum = 2.5f - atknum;
        }

        public override long getAtk()
        {
            return (long)(atknum * level);
        }
        public override long getDef()
        {
            return (long)(defnum * level);
        }

        public void checkLevelUp()
        {
            int requiredExp = (int)(2 * Math.Pow(1.4f, level));
            while (this.exp >= requiredExp)
            {
                this.exp -= requiredExp;
                LevelUp();
                requiredExp = (int)(2 * Math.Pow(1.4f, level));
            }
        }
        //용사의 돈 =8 * 1.36^(레벨) + 8*(레벨)
        public long getEarnedMoney(long wave)
        {
            return (long)(8 * Math.Pow(1.36,
                level) + 8 * level);
        }

        public void setLevel(int level)
        {
            this.level = level - 1;
            LevelUp();
        }
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (this.pos.X > Config.mapWidth - this.TextWidth)
            {
                this.pos.X = Config.mapWidth - this.TextWidth;
            }

            this.hitpoint = (float)Math.Min(this.hitpoint+gameTime.ElapsedGameTime.TotalSeconds * this.maxhitpoint/100.0, 
                this.maxhitpoint);

            this.size = level * 1 + 15;

            if (this.level < 5)
                this.comment = "아무것도 모르는";
            else if (this.level < 10)
                this.comment = "갓 세상에 나온";
            else if (this.level < 15)
                this.comment = "몬스터를 만나본";
            else if (this.level < 20)
                this.comment = "싸움을 해 본";
            else if (this.level < 25)
                this.comment = "칼좀 휘둘러 본";
            else if (this.level < 30)
                this.comment = "몬스터 좀 잡아 본";
            else if (this.level < 35)
                this.comment = "덩치만 큰";
            else if (this.level < 40)
                this.comment = "싹수가 보이는";
            else if (this.level < 45)
                this.comment = "슬슬 위협적인";
            else if (this.level < 50)
                this.comment = "몬스터들이 무서워하는";
            else if (this.level < 55)
                this.comment = "산더미만한";
            else if (this.level < 60)
                this.comment = "추앙 받는";
            else if (this.level < 70)
                this.comment = "경이로운";
            else if (this.level < 80)
                this.comment = "영웅적인";
            else if (this.level < 90)
                this.comment = "신에 가까워 진";
            else
                this.comment = "불멸의";
        }
        protected override void LevelUp()
        {
            level++;

            float hpPersent = (float)hitpoint / maxhitpoint;

            this.maxhitpoint = (long)(80 + 20 * level + 0.2 * Math.Pow(level, 3));
            this.hitpoint = maxhitpoint * hpPersent;

        }
    }
}
